package com.atguigu.gmall.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolExecutorConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                8,      //看是cpu密集型n+1   还是i/o密集型2n
                30, //最大线程数
                3L,     //时间
                TimeUnit.SECONDS,       //单位是秒
                new ArrayBlockingQueue<>(3),    //阻塞队列大小
                Executors.defaultThreadFactory(),       //工厂
                new ThreadPoolExecutor.AbortPolicy()        //拒绝策略
        );
        return threadPoolExecutor;
    }
}
